package com.ruoyi.web.wx.controller;

import java.util.List;
import java.util.UUID;

import com.ruoyi.web.wx.entity.TrashSetting;
import com.ruoyi.web.wx.service.ITrashSettingService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 回收垃圾设置奖励 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-08-27
 */
@Controller
@RequestMapping("/system/trashSetting")
public class TrashSettingController extends BaseController
{
    private String prefix = "system/trashSetting";
	
	@Autowired
	private ITrashSettingService trashSettingService;
	
	@RequiresPermissions("system:trashSetting:view")
	@GetMapping()
	public String trashSetting()
	{
	    return prefix + "/trashSetting";
	}
	
	/**
	 * 查询回收垃圾设置奖励列表
	 */
	@RequiresPermissions("system:trashSetting:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TrashSetting trashSetting)
	{
		startPage();
        List<TrashSetting> list = trashSettingService.selectTrashSettingList(trashSetting);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出回收垃圾设置奖励列表
	 */
	@RequiresPermissions("system:trashSetting:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TrashSetting trashSetting)
    {
    	List<TrashSetting> list = trashSettingService.selectTrashSettingList(trashSetting);
        ExcelUtil<TrashSetting> util = new ExcelUtil<TrashSetting>(TrashSetting.class);
        return util.exportExcel(list, "trashSetting");
    }
	
	/**
	 * 新增回收垃圾设置奖励
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存回收垃圾设置奖励
	 */
	@RequiresPermissions("system:trashSetting:add")
	@Log(title = "回收垃圾设置奖励", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TrashSetting trashSetting)
	{		trashSetting.setId(UUID.randomUUID().toString().replaceAll("-",""));
		trashSetting.setStatus("1");
	return toAjax(trashSettingService.insertTrashSetting(trashSetting));
	}

	/**
	 * 修改回收垃圾设置奖励
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		TrashSetting trashSetting = trashSettingService.selectTrashSettingById(id);
		mmap.put("trashSetting", trashSetting);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存回收垃圾设置奖励
	 */
	@RequiresPermissions("system:trashSetting:edit")
	@Log(title = "回收垃圾设置奖励", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TrashSetting trashSetting)
	{		
		return toAjax(trashSettingService.updateTrashSetting(trashSetting));
	}
	
	/**
	 * 删除回收垃圾设置奖励
	 */
	@RequiresPermissions("system:trashSetting:remove")
	@Log(title = "回收垃圾设置奖励", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(trashSettingService.deleteTrashSettingByIds(ids));
	}
	
}
